/**
* +----------------------------------------------------------------------
* | 友得云客  - 开启房产营销新纪元
* +----------------------------------------------------------------------
* | Copyright (c) 2019~2023 优得（西安）信息科技有限公司版权所有
* +----------------------------------------------------------------------
* | Licensed 友得云客不是自由软件 未经允许不可移除相关版权
* +----------------------------------------------------------------------
* | Author: www.youdeyunke.com
* +----------------------------------------------------------------------
*/
import request from '@/utils/request'

export function getToken (data) {
    // data like : { dir: 'aaa', filename: 'abc.exe'}
    return request({
        url: '/v1/qiniu_token/',
        method: 'POST',
        data
    })
}

export function upload (file) {
    console.log('file', file)
    return getToken({
        filename: file.name,
    }).then(resp => {
        const data = new FormData()
        var token = resp.data.token
        var key = resp.data.key
        data.append('token', token)
        data.append('file', file)
        data.append('key', key)
        return request({
            // url: 'https://upload-z0.qiniup.com',
            url: 'https://up.qbox.me',
            method: 'POST',
            data: data
        })
    })
}
